<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<style>
.top-area{
	 height:100px;
	 width:100%;
	 display:flex;
	 flex-direction: row;
	 margin-top:30px;
}
.top-item{
	height:80px;
	width:25%;
	font-size:20px;
}
.maskback{
	position:fixed;
	width:100%;
	height:100%;
	top:0px;
	background:rgba(0,0,0,0.7);
}
.mainback{
        width: 25%;
    height: 380px;
    background: #fff;
    margin: 0 auto;
    margin-top: 21%;
    padding-top: 10px;
    padding-left: 10px;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>
<div class="store-area">
	<div class="store-item">${storeName}</div>
</div>
<div class="top-area">
	<div class="top-item">销售额：${totalSale}</div>
	<div class="top-item">利润额：${totalProfit}</div>
	<div class="top-item">店铺：${totalStore}</div>
	<div class="top-item">订单量：${totalOrder}</div>
</div>
<div class="search-field">
    <!-- <span class="field-cont">
        <span class="field-cont-title">商品名称</span>
        <input type="text" class="summer-input" id="spuName"/>
    </span> -->
    
     <span class="field-cont">
        <span class="field-cont-title">订单号</span>
        <input type="text" class="summer-input" id="orderNum"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">订单状态</span>
        <input type="text" class="summer-input" id="status"/>
    </span>
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>订单号</th>
		        <th>实付额</th>
				<th>单量</th>
				<th>利润</th>
				<th>提交时间</th>
				<th>确认时间</th>
				<th>订单状态</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<div style="display: none" class="maskback">
     <div class="mainback">
     	 <div class="form-cont" style="top:40px;">
     	    <input type="hidden" name="id" id="id"/>
	        <p class="form-cont-title"><span class="field-required">*</span>订单号</p>
	        <input type="text" id="orderNo" disabled name="orderNo" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-cont" style="top:40px;">
	        <p class="form-cont-title"><span class="field-required">*</span>物流公司</p>
	        <input type="text" id="expressId" name="expressId" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-cont" style="top:40px;">
	        <p class="form-cont-title"><span class="field-required">*</span>快递编号</p>
	        <input type="text" id="expressNo" name="expressNo" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-cont" style="top:40px;">
	        <p class="form-cont-title"><span class="field-required">*</span>包裹数量</p>
	        <input type="text" id="expCount" name="expCount" class="summer-input summer-validatebox" /> 
	     </div>
	     <div class="form-btn-wrapper" id="funcbar" style="margin-top: 100px;">
	        <a id="save" href="javascript:;" class="btn btn-ok btn-normal  wave distance-right" >保存</a>
	        <a class="btn btn-normal" id="close">关闭</a>
	     </div>
     </div>
</div>

<script>
	//请求url
	var CONST_URL = {
		STORE_LIST: basePath + '${common_url}storeList',
		INIT_CITY_DETAIL: basePath + '${common_url}initCityDetail',
		INIT_CITY_STORE_DETAIL: basePath + '${common_url}initCityStoreDetail',
		ORDER_LIST: basePath + '${common_url}orderList',
		INIT_ORDER_DETAIL: basePath + '${common_url}initOrderdetail',
		INIT_SEND: basePath + '${common_url}initSend',
		SEND: basePath + '${common_url}send',
		GET_EXPRESS_ID: basePath + '${common_url}getProjectExpress',
		INIT_VIEW: basePath + '${common_url}initView'
	};
	
    var  saleId,
    	 uid,
    	 cityId,
    	 permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	console.log(permission);
    	uid = ${uid};
    	saleId = ${saleId};
    	cityId = ${cityId};
    	//初始化下拉选项
    	$('#identity').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_PARTNER_APPLY_TYPE'
        });
    	//物流公司下拉列表
    	$('#expressId').combobox({
            url : CONST_URL.GET_EXPRESS_ID, 
            valueField : 'id',
            async:false,
            textField : 'expressCompany'
        });
        //orderDetail
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initOrderdetail"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_ORDER_DETAIL + '?id=' + id+"&storeId=" + uid+"&saleId="+saleId+"&cityId="+cityId;
        });
        //发货初始化
        $("#t-wrap").on('click','a[data-permit="${name_english}:initSend"]',function(){
        	var $this = $(this),
        	orderNo = $this.closest('tr').find('td[data-field="orderNum"]').attr('data-value');
        	$("#orderNo").val(orderNo);
        	$(".maskback").show();
        });
      //initView
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_VIEW + '?id=' + id;
        });
        // 查询按钮
        $('#search').on('click', reloadTable);
        //提交弹窗，发货
        $("#save").on('click',sendOrder);
        //关闭弹窗
        $("#close").on('click',function(){
        	$(".maskback").hide();
        });
      	//返回按钮
   		$('#backBtn, #goBack').on('click',backMain);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#partnerName').val('');
        	$('#totalInMoneySlef').val('');
        	$('#totalOrders').val('');
        	$('#totalProfit').val('');
        	reloadTable();
        });
        
       createTable();
        
    });
    //订单发货
    function sendOrder(){
    	var orderNo = $("#orderNo").val(),
    	expressId = $('#expressId').combobox('getValue'),
    	expressNo = $("#expressNo").val(),
    	expCount = $("#expCount").val();
    	$.ajax({
			   url: CONST_URL.SEND,//请求的后台地址
			   data:{
					"orderNo": orderNo,
					"expressId": expressId,
					"expressNo": expressNo,
					"expCount": expCount
				},//前台传给后台的参数
			   success: function(data){//msg:返回值
				   console.log(data);
				 if(data.msg != "null"){
					 alert(data.data.msg);
				 }
			     $(".maskback").hide();
			     reloadTable();
			   }
			});

    	
    }
  	//返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"storeId": uid
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.ORDER_LIST,
    			param: {
    				"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"storeId": uid
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'orderNum'
    		     },
    		     {
    		    	 field: 'actualPay'
    		     },
    		     {
    		    	 field: 'totalCount'
    		     },
    		     {
    		    	field:'totalProfit' 
    		     },
    		     {
    		    	 field:'createTime'
    		     },
    		     {
    		    	 field:'receiveTime'
    		     },
    		     {
    		    	 field:'state'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 if(rowData.state == "待发货"){
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 2,    //显示数量
        		    			 permit: ['${name_english}:initOrderdetail','${name_english}:initSend'] //需要的权限按钮
        		    		 });
    		    		 }else{
    		    			 return $.funcbar({
        		    			 data: permission,    //请求的数据
        		    			 type: 'text',     //类型
        		    			 display: 2,    //显示数量
        		    			 permit: ['${name_english}:initOrderdetail'] //需要的权限按钮
        		    		 });
    		    		 }
    		    		 
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
  //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_CITY_DETAIL+'?pId=' + saleId+"&cityId="+cityId;
    }
</script>
</body>
</html>